This is my first time writing a script and not sure where to start but here is the basic idea of what I want:
I have three attributes (Requirement, Parent ID, and Absolute Number)
This is what I want to do:
If Requirement is True and Parent ID is blank use the absolute number as Parent ID
Any help would be appreciated.
Regards
gund - Mon Mar 08 13:07:37 EST 2010 |
|
Re: Help doors36677 - Mon Mar 08 13:47:35 EST 2010
Since it appears that you are new to DOORS, you might be better off not using a script and learn how to to this task using export and import by spreadsheet. Learn the basics first.
|
|
Re: Help llandale - Mon Mar 08 15:32:22 EST 2010
Object obj Module mCurr = current
if (
null mCurr or !isEdit(mCurr))
{errorBox(
"Run from open Edit module"); halt
} AttrDef ad = find(mCurr,
"Parent ID")
if (
null ad or !ad.object)
{errorBox(
"Module has no 'Parent ID' object attribute"); halt
}
for obj in entire (current Module)
do
{
if (isDeleted(obj))
continue
// ignore deleted object
if (probeAttr_(obj,
"Requirement") !=
"True")
continue
// ignore non-Requirement
if (!
null probeAttr_(obj,
"Parent ID"))
continue
// Parent ID already set
// Initialize the null Parent ID: obj.
"Parent ID" = probeAttr_(obj,
"Absolute Number")
}
// end for all objects in the module
|
|
Re: Help gund - Mon Mar 08 16:56:55 EST 2010
Thanks for the help,
I took a stab at it myself and this is what I have
pragma runLim,0
Module m
Object o
string reqID
if (null current Module)
{
ack "Please run this program from a module"
halt
}
if (!isEdit current)
{
ack "Current module must be editable to run this."
halt
}
for o in current Module do
{
reqID = o."Requirement ID"
if (reqID == "True")
{
if (o."Parent ID" != null)
{
{
int number = o."Absolute Number"
o."Parent ID" = o."Absolute number"""
}
}
}
}
Now the problem I'm having is even if Parent ID already has something in it it gets replaced with the absolute number. So if parent ID already = 5000 and Absolute ID = 2 then parent ID would get replaced with 2. I'm trying to get it where the parent ID wont change if it already has a value.
|
|
Re: Help SystemAdmin - Mon Mar 08 17:32:19 EST 2010 gund - Mon Mar 08 16:56:55 EST 2010
Thanks for the help,
I took a stab at it myself and this is what I have
pragma runLim,0
Module m
Object o
string reqID
if (null current Module)
{
ack "Please run this program from a module"
halt
}
if (!isEdit current)
{
ack "Current module must be editable to run this."
halt
}
for o in current Module do
{
reqID = o."Requirement ID"
if (reqID == "True")
{
if (o."Parent ID" != null)
{
{
int number = o."Absolute Number"
o."Parent ID" = o."Absolute number"""
}
}
}
}
Now the problem I'm having is even if Parent ID already has something in it it gets replaced with the absolute number. So if parent ID already = 5000 and Absolute ID = 2 then parent ID would get replaced with 2. I'm trying to get it where the parent ID wont change if it already has a value.
You can generally test for presence of a string or integer and only do assignment if the right conditions apply:
See:
//------------------------------------------------------------------------------
// BEGIN WHITE UTILS
//------------------------------------------------------------------------------ string rightTrim(string s)
{
if (s ==
null)
return
"";
int first = 0;
int last = length(s) - 1;
while( (last > -1) && (isspace(s[last])) )
{ last--;
}
return(s[first:last]);
} string leftTrim(string s)
{
if (s ==
null)
return
"";
int first = 0;
int last = length(s) - 1;
while( (isspace(s[first])) && (first < last) )
{ first++;
}
return(s[first:last]);
} string trim(string s)
{
return(leftTrim(rightTrim(s)));
} bool isFinite(string str)
{
if (str ==
null) str =
"";
return (length(trim(str)) > 0);
} bool isBlankOrInteger(string str)
{ bool isBlankOrInteger =
false; str = trim(str);
if (length(str) == 0)
{ isBlankOrInteger =
true;
}
else
if (isValidInt(str))
{ isBlankOrInteger =
true;
}
return isBlankOrInteger;
}
//------------------------------------------------------------------------------
// END WHITE UTILS
//------------------------------------------------------------------------------
|
|
Re: Help llandale - Tue Mar 09 16:01:50 EST 2010 gund - Mon Mar 08 16:56:55 EST 2010
Thanks for the help,
I took a stab at it myself and this is what I have
pragma runLim,0
Module m
Object o
string reqID
if (null current Module)
{
ack "Please run this program from a module"
halt
}
if (!isEdit current)
{
ack "Current module must be editable to run this."
halt
}
for o in current Module do
{
reqID = o."Requirement ID"
if (reqID == "True")
{
if (o."Parent ID" != null)
{
{
int number = o."Absolute Number"
o."Parent ID" = o."Absolute number"""
}
}
}
}
Now the problem I'm having is even if Parent ID already has something in it it gets replaced with the absolute number. So if parent ID already = 5000 and Absolute ID = 2 then parent ID would get replaced with 2. I'm trying to get it where the parent ID wont change if it already has a value.
Its confusing and unclear.
obj.NameAttr ... ss not a string, its a data type "Attr__". The only time its 'null' is when obj or NameAttr don't exist, in which case you get DXL abort errors.
string AttrValu = obj.NameAttr ... is specifically allowed and you can find that in the DXL manual.
obj.NameAttr "" ... is specifically allowed, turning an attr reference into the value from that obj-attr.
if (null obj.NameAttr) ... means 'if the attr reference is null' which it is not. You want to do this:
if (null obj.NameAttr "") ... which retrieves the value, and checks THAT for null
if (o."Parent ID" "" != null) ... in your case
|
|